﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;


namespace Besture.UI.Admin.User
{
    public partial class RolesSet : BasePage
    {
        /// <summary>
        /// 
        /// </summary>
        public string _txtNContentValue = string.Empty;

        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {
            //自动序号加载
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id <= 0)
            {
                return;
            }
            RolesDac dac = new RolesDac();
            RolesModel model = dac.GetModel(id);
            txtRolesName.Text = model.Name;
            txtUserPermissions.Text = model.Permissions;
            txtRemark.Text = model.Remarks;
        }
        #endregion

        #region 保存

        protected void btnSubmit_Click(object sender, EventArgs eventArgs)
        {
            RolesDac dac = new RolesDac();
            RolesModel model = null;
            //添加
            if (!EditPage)
            {
                model = new RolesModel();
                model.Name = txtRolesName.Text.Trim();
                model.Remarks = txtRemark.Text.Trim();
                model.Permissions = txtUserPermissions.Text.Trim(',');
                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(ID);
                model.Name = txtRolesName.Text.Trim();
                model.Permissions = txtUserPermissions.Text.Trim(',');
                model.Remarks = txtRemark.Text.Trim();
                dac.Update(model);
            }
            FunHelper.Alert("保存成功", "RolesList.aspx");
        }
        #endregion

        #region 取消

        public void btnCanel_Click(object sender, EventArgs eventArgs)
        {
            RedirectUrl("RolesList.aspx");
        }

        #endregion
    }
}